/**
 * Created by huachuan on 2016/1/11.
 */
angular.module('mecollectservice',[])
  //我关注的Service
  .factory('MeCollect', function($resource,$rootScope,ENV,Storage) {
    var memberId = Storage.get('member').member_id;
    //访问的地址
    var APIUrl = ENV.api;
    //接收返回值
    var wineCollectListJson,meetingCollectListJson,messageCollectListJson;
    var bookCollectListJson,videoCollectListJson,homeCollectListJson,chapterCollectListJson;
    var no2CollectJson;
    //获取$resource
    var getMeWineCollectListResource = $resource(APIUrl + 'meCollect/getMeWineCollectList.do');
    var getMeMeetingCollectListResource = $resource(APIUrl + 'meCollect/getMeMeetingCollectList.do');
    var getMeHomeCollectListResource = $resource(APIUrl + 'meCollect/getMeHomeCollectList.do');
    var getMeMessageCollectListResource = $resource(APIUrl + 'meCollect/getMeMessageCollectList.do');
    var getMeBookCollectListResource = $resource(APIUrl + 'meCollect/getMeBookCollectList.do');
    var getMeVideoCollectListResource = $resource(APIUrl + 'meCollect/getMeVideoCollectList.do');
    var getMeChapterCollectListResource = $resource(APIUrl + 'meCollect/getMeChapterCollectList.do');
    var deleteCollectListResource = $resource(APIUrl + 'meCollect/deleteCollect.do');

    return {
      //取消收藏
      no2Collect:function(mcIds){
        deleteCollectListResource.save({
          mcIds:mcIds,
          member_id:memberId
        },function(response){
          no2CollectJson = response;
          $rootScope.$broadcast('MeCollect.noCollectWineUpdated');
        });
      },
      getNo2CollectJson:function(){
        return no2CollectJson;
      },
      //获取到收藏的酒款
      getWineList:function(memberId){
        getMeWineCollectListResource.save({
          member_id:memberId
        },function(response){
          wineCollectListJson = response;
          $rootScope.$broadcast('MeCollect.WineCollectListUpdated');
        });
      },
      getWineListJson:function(){
        return wineCollectListJson;
      },
      //获取到收藏的约局
      getMeMeetingList:function(memberId){
        getMeMeetingCollectListResource.save({
          member_id:memberId
        },function(response){
          meetingCollectListJson = response;
          $rootScope.$broadcast('MeCollect.MeetingCollectListUpdated');
        });
      },
      getMeMeetingListJson:function(){
        return meetingCollectListJson;
      },
      //获取到收藏的酒窝
      getHomeList:function(memberId){
        getMeHomeCollectListResource.save({
          member_id:memberId
        },function(response){
          homeCollectListJson = response;
          $rootScope.$broadcast('MeCollect.HomeCollectListUpdated');
        });
      },
      getHomeListJson:function(){
        return homeCollectListJson;
      },
      //获取到收藏的资讯
      getMessageList:function(memberId){
        getMeMessageCollectListResource.save({
          member_id:memberId
        },function(response){
          messageCollectListJson = response;
          $rootScope.$broadcast('MeCollect.MessageCollectListUpdated');
        });
      },
      getMessageListJson:function(){
        return messageCollectListJson;
      },
      //获取到收藏的书籍
      getBookList:function(memberId){
        getMeBookCollectListResource.save({
          member_id:memberId
        },function(response){
          bookCollectListJson = response;
          $rootScope.$broadcast('MeCollect.BookCollectListUpdated');
        });
      },
      getBookListJson:function(){
        return bookCollectListJson;
      },
      //获取到收藏的视频
      getVideoList:function(memberId){
        getMeVideoCollectListResource.save({
          member_id:memberId
        },function(response){
          videoCollectListJson = response;
          $rootScope.$broadcast('MeCollect.VideoCollectListUpdated');
        });
      },
      getVideoListJson:function(){
        return videoCollectListJson;
      },
      //获取到收藏的章节
      getChapterList:function(memberId){
        getMeChapterCollectListResource.save({
          member_id:memberId
        },function(response){
          chapterCollectListJson = response;
          $rootScope.$broadcast('MeCollect.ChapterCollectListUpdated');
        });
      },
      getChapterListJson:function(){
        return chapterCollectListJson;
      }
    }
  })

